package com.yiyang.controller;


import com.yiyang.mapper.RoomMapper;
import com.yiyang.pojo.Room;
import com.yiyang.pojo.vo.PageResult;
import com.yiyang.pojo.vo.Result;
import com.yiyang.service.RoomService;
import com.yiyang.utils.BizCode;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/room")
@Tag(name = "RoomController",description = "房间信息")
public class RoomController {

    @Resource
    private RoomService roomService;

    // 根据id查询房间信息
    @GetMapping("/{id}")
    public Result<Room> getRoomById(@PathVariable("id") Integer id){
        return roomService.getRoomById(id);
    }

    // 查询楼宇的全部房间信息
    @GetMapping
    public Result<PageResult<List<Room>>> getAllRoom(
            @RequestParam(name = "currentPage",defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize,
            @RequestParam(name = "num",defaultValue = "") String num,
            @RequestParam(name = "floor",defaultValue = "") String floor
    ){
        return roomService.getAllRoom(currentPage,pageSize,num,floor);
    }

    // 添加房间信息
    @PutMapping
    public Result<Void> addRoom(@RequestBody Room room){
        return roomService.addRoom(room);
    }

    // 修改房间信息
    @PostMapping
    public Result<Void> updateRoom(@RequestBody Room room){
        return roomService.updateRoom(room);
    }


    // 根据id删除对应房间信息
    @DeleteMapping
    public Result<Void> deleteRoom(@PathVariable("id") Integer id){
        return roomService.deleteRoom(id);
    }
}
